package com.wanxi.app.service.user;


import com.wanxi.user.api.AddressFeign;
import com.wanxi.user.api.ShoppingCartFeign;
import com.wanxi.user.api.UserFeign;
import com.wanxi.user.domain.dto.AddressDefaultDto;
import com.wanxi.user.domain.dto.AddressDto;
import com.wanxi.user.domain.entity.Address;
import com.wanxi.user.domain.result.UserResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author:wgy
 * @Data：2022/1/12 10:05
 */
@Service
public class AddressService {

    @Resource
    private AddressFeign addressFeign;

    public UserResult<List<Address>> findAddressByUserId(int userId){
        UserResult<List<Address>> byUserId = addressFeign.findByUserId((int)userId);
        return byUserId;
    }

    public UserResult<Boolean> updateAddress(AddressDto addressDto){
        UserResult<Boolean> byUserId = addressFeign.updateAddress(addressDto);
        return byUserId;
    }

    public UserResult<Long> addAddress(AddressDto addressDto){
        UserResult<Long> booleanUserResult = addressFeign.addAddress(addressDto);
        return booleanUserResult;
    }


    public UserResult<String> updateAddressDefault(AddressDefaultDto addressDefaultDto){
        UserResult<Boolean> booleanUserResult = addressFeign.updateAddressDefault(addressDefaultDto);
        if (booleanUserResult.getData()){
            return UserResult.success("修改成功");
        }
        return UserResult.failed("修改成功");
    }

    public UserResult<String> delAddress(long addressId){
        UserResult<Boolean> booleanUserResult = addressFeign.delAddress(addressId);
        if (booleanUserResult.getData()){
            return UserResult.success("删除成功");
        }
        return UserResult.failed("删除成功");
    }






}
